<?php
/**
 * Created by PhpStorm.
 * User: yuanjie
 * Date: 15/12/21
 * Time: 下午2:27
 */
use EasyWeChat\Foundation\Application;
class WeChatMenuController extends BaseController {

    public function current(){
        $wx = Config::get('wechat.CHEPIN');
        $options = $wx['OPTION'];

        $app = new Application($options);
        $menu = $app->menu;
        $current_menus = $menu->current()->toArray();
        $menu->add($current_menus['selfmenu_info']['button']);
        return json_encode($current_menus['selfmenu_info']['button']);
    }

/*
    public function set_menu(){
        $validator = Validator::make(Input::all(),
            array(
                'token' => 'required',
                'menu' => 'required',
            )
        );

        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("sce_error.login_args_error_1001");
                break;
            }

            //传入参数
            $token = Input::get('token');
            $menu = Input::get('menu'); //菜单结构体

            //验证token
            //需要修改为微博调用用户的token验证
//            $engineer_data = MaintenanceEngineers::getEngineerByToken($token);
//            if(is_numeric($engineer_data) && $engineer_data < 0){
//                $response = Lang::get("sce_error.user_token_not_exist_1004");
//                break;
//            }
            $menuService = new Menu(Config::get('wechat.APP_ID'), Config::get('wechat.APP_SECRET'));
            $item_yihao = new MenuItem('壹号', 'click', 'YIHAO_001');
            $item_yihao->buttons(
                array(
                    new MenuItem('官网','view','http://www.baidu.com'),
                    new MenuItem('产品功能','view','http://www.baidu.com'),
                    new MenuItem('线下门店','view','http://www.baidu.com')
                )
            );
            $items[] = $item_yihao;

            $item_hui = new MenuItem('惠', 'click', 'HUI_001');
            $item_hui->buttons(
                array(
                    //new MenuItem('年会','view','https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx664e3e4c6b3b1267&redirect_uri=http%3A%2F%2Fapi.yangche1hao.com%2fwechat%2fauth&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect'),
                    new MenuItem('年会','view','http://www.hixianchang.com/m/445d7705021e40d4b6e34b86ff17b4a0.html'),
                )
            );
            $items[] = $item_hui;

            $item_yangche = new MenuItem('养车','view','http://wechat.yangche1hao.com');
            $items[] = $item_yangche;

            try {
                $menuService->set($items);
                $response = array('code' => 0, 'msg' => 'ok', 'result' => '设置成功！');
            } catch (Exception $e) {
                $response = array('code' => 0, 'msg' => 'ok', 'result' => '设置失败：' . $e->getMessage());
            }
        } while (false);
        return json_encode($response);
    }
*/
}